﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
namespace PeisongWeb
{
    public partial class sellerAssessmentlist : adminPage
    {
        public int Id
        {
            get
            {
                int id = 0;
                int.TryParse(Request.QueryString["company"], out id);
                return id;
            }
            set
            {
                Id = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (hasPermission("FD", 1))
                {
                    bind();
                    this.selCom.Text = logic.company.getById(Id).Company;
                }
                else
                {
                    Library.Script.ClientMsg("没有操作权限");
                }
            }
        }


        void bind()
        {
            StringBuilder wheres = new StringBuilder();
            wheres.AppendFormat("sellerId={0}", Id);
            DataSet ds = logic.assessmentWeek.select_AssessmentWeek(wheres.ToString(), "endDt desc", this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bind();
        }


        /// <summary>
        /// 预览本周考核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            //if (DateTime.Now.DayOfWeek <= DayOfWeek.Friday && DateTime.Now.Hour<17)//礼拜五之前，并且在下午5点前可以预览本周的考核信息
            //{
                ScriptManager1.AddScript(string.Format("window.open('sellerAssessment_report.aspx?sellerId={0}&tag=0&id=0','_blank');", Id));
            //}
            //else
            //{
            //    Library.Script.ClientMsg("本周评估已生成，没有预览的内容！");
            //}
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rpt_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal lit = e.Item.FindControl("lit_frc") as Literal;

                DataRowView dataView = e.Item.DataItem as DataRowView;

                DataRow dt = DAL.DbHelper.ExecuteDataRow("P_Assessment_ByidDt", Id, dataView["startDt"], dataView["endDt"]);
                lit.Text = dt["sumass"].ToString() == string.Empty ? "100" :(100+Convert.ToDouble(dt["sumass"])).ToString();

            }
        }
    }
}
